home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / disasm.zip / ASMTUTR1.DOC < prev    next >
Text File  |  1988-06-03  |  23KB  |  414 lines

  1.  
  2.  
  3.  
  4.                     IBM Personal Computer Assembly
  5.                          Language Tutorial
  6.  
  7.                           Joshua Auerbach
  8.                           Yale University
  9.                         Yale Computer Center
  10.                          175 Whitney Avenue
  11.                            P. O. Box 2112
  12.                      New Haven, Connecticut 06520
  13.                          Installation Code YU
  14.                  Integrated Personal Computers Project
  15.                         Communications Group
  16.                  Communications and Data Base Division
  17.                             Session C316
  18.  
  19.  
  20. This talk is for people who are just getting started with the PC MACRO
  21. Assembler.  Maybe you are just contemplating doing some coding in
  22. assembler, maybe you have tried it with mixed success.  If you are here to
  23. get aimed in the right direction, to get off to a good start with the
  24. assembler, then you have come for the right reason.  I can't promise you'll
  25. get what you want, but I'll do my best.
  26. On the other hand, if you have already turned out some working assembler
  27. code, then this talk is likely to be on the elementary side for you.  If
  28. you want to review a few basics and have no where else pressing to go, then
  29. by all means stay.
  30.  
  31. Why Learn Assembler?
  32. ____________________
  33. Why Learn Assembler?
  34. Why Learn Assembler?
  35. Why Learn Assembler?
  36. The reasons for LEARNING assembler are not the same as the reasons for
  37. USING it in a particular application.  But, we have to start with some of
  38. the reasons for using it and then I think the reasons for learning it will
  39. become clear.
  40. First, let's dispose of a bad reason for using it.  Don't use it just
  41. because you think it is going to execute faster.  A particular sequence of
  42. ordinary bread-and-butter computations written in PASCAL, C, FORTRAN, or
  43. compiled BASIC can do the job just about as fast as the same algorithm
  44. coded in assembler.  Of course, interpretive BASIC is slower, but if you
  45. have a BASIC application which runs too slow you probably want to try com-
  46. IBM PC Assembly Language Tutorial                                         1
  47.  
  48.  
  49. piling it before you think too much about translating parts of it to
  50. another language.
  51. On the other hand, high level languages do tend to isolate you from the
  52. machine.  That is both their strength and their weakness.  Usually, when
  53. implemented on a micro, a high level language provides an escape mechanism
  54. to the underlying operating system or to the bare machine.  So, for
  55. example, BASIC has its PEEK and POKE.  But, the route to the bare machine
  56. is often a circuitous one, leading to tricky programming which is hard to
  57. follow.
  58. For those of us working on PC's connected to SHARE-class mainframes, we are
  59. generally concerned with three interfaces:  the keyboard, the screen, and
  60. the communication line or lines.  All three of these entities raise machine
  61. dependent issues which are imperfectly addressed by the underlying operat-
  62. ing system or by high level languages.
  63. Sometimes, the system or the language does too little for you.  For
  64. example, with the asynch adapter, the system provides no interrupt handler,
  65. no buffer, and no flow control.  The application is stuck with the respon-
  66. sibility for monitoring that port and not missing any characters, then
  67. deciding what to do with all errors.  BASIC does a reasonable job on some
  68. of this, but that is only BASIC.  Most other languages do less.
  69. Sometimes, the system may do too much for you.  System support for the key-
  70. board is an example.  At the hardware level, all 83 keys on the keyboard
  71. send unique codes when they are pressed, held down, and released.  But,
  72. someone has decided that certain keys, like Num Lock and Scroll Lock are
  73. going to do certain things before the application even sees them and can't
  74. therefore be used as ordinary keys.
  75. Sometimes, the system does about the right amount of stuff but does it less
  76. efficiently then it should.  System support for the screen is in this
  77. class.  If you use only the official interface to the screen you sometimes
  78. slow your application down unacceptably.  I said before, don't use assem-
  79. bler just to speed things up, but there I was talking about mainline code,
  80. which generally can't be speeded up much by assembler coding.  A critical
  81. system interface is a different matter:  sometimes we may have to use
  82. assembler to bypass a hopelessly inefficient implementation.  We don't want
  83. to do this if we can avoid it, but sometimes we can't.
  84. Assembly language code can overcome these deficiencies.  In some cases, you
  85. can also overcome these deficiencies by judicious use of the escape valves
  86. which your high level language provides.  In BASIC, you can PEEK and POKE
  87. and INP and OUT your way around a great many issues.  In many other lan-
  88. guages you can issue system calls and interrupts and usually manage, one
  89. way or other, to modify system memory.  Writing handlers to take real-time
  90. hardware interrupts from the keyboard or asynch port, though, is still
  91. going to be a problem in most languages.  Some languages claim to let you
  92. do it but I have yet to see an acceptably clean implementation done that
  93. way.
  94. The real reason while assembler is better than "tricky POKEs" for writing
  95. machine-dependent code, though, is the same reason why PASCAL is better
  96. than assembler for writing a payroll package:  it is easier to maintain.
  97. IBM PC Assembly Language Tutorial                                         2
  98.  
  99.  
  100. Let the high level language do what it does best, but recognize that there
  101. are some things which are best done in assembler code.  The assembler,
  102. unlike the tricky POKE, can make judicious use of equates, macros, labels,
  103. and appropriately placed comments to show what is really going on in this
  104. machine-dependent realm where it thrives.
  105. So, there are times when it becomes appropriate to write in assembler; giv-
  106. en that, if you are a responsible programmer or manager, you will want to
  107. be "assembler-literate" so you can decide when assembler code should be
  108. written.
  109. What do I mean by "assembler-literate?"  I don't just mean understanding
  110. the 8086 architecture; I think, even if you don't write much assembler code
  111. yourself, you ought to understand the actual process of turning out assem-
  112. bler code and the various ways to incorporate it into an application.  You
  113. ought to be able to tell good assembler code from bad, and appropriate
  114. assembler code from inappropriate.
  115.  
  116. Steps to becoming ASSEMBLER-LITERATE
  117. ____________________________________
  118. Steps to becoming ASSEMBLER-LITERATE
  119. Steps to becoming ASSEMBLER-LITERATE
  120. Steps to becoming ASSEMBLER-LITERATE
  121. 1.  Learn the 8086 architecture and most of the instruction set.  Learn
  122.     what you need to know and ignore what you don't.  Reading:  The 8086
  123.     Primer by Stephen Morse, published by Hayden.  You need to read only
  124.     two chapters, the one on machine organization and the one on the
  125.     instruction set.
  126. 2.  Learn about a few simple DOS function calls.  Know what services the
  127.     operating system provides.  If appropriate, learn a little about other
  128.     systems too.  It will aid portability later on.  Reading:  appendices D
  129.     and E of the PC DOS manual.
  130. 3.  Learn enough about the MACRO assembler and the LINKer to write some
  131.     simple things that really work.  Here, too, the main thing is figuring
  132.     out what you don't need to know.  Whatever you do, don't study the sam-
  133.     ple programs distributed with the assembler unless you have nothing
  134.     better!
  135. 4.  At the same time as you are learning the assembler itself, you will
  136.     need to learn a few tools and concepts to properly combine your assem-
  137.     bler code with the other things you do.  If you plan to call assembler
  138.     subroutines from a high level language, you will need to study the
  139.     interface notes provided in your language manual.  Usually, this forms
  140.     an appendix of some sort.  If you plan to package your assembler rou-
  141.     tines as .COM programs you will need to learn to do this.  You should
  142.     also learn to use DEBUG.
  143. 5.  Read the Technical Reference, but very selectively.